<?php

	$user = $controller->getCurrentUser();
	
	if ($user->isAllowedTo(GRADE_CONSULT_BOOK))
	{
		$elementsAllowed = array('book','author','serie','publisher');
		$element = $request->getParam('element');
		$id = $request->getParam('id');	
		
		if (!$id || !is_numeric($id) || !in_array($element, $elementsAllowed))
		{
			$controller->addError('Un param&egrave;tre est erron&eacute; ! Veuillez utiliser les liens du site pour naviguer !');
			$controller->forward('index');	
		}
		else
		{
			$object = call_user_func(array($element, 'singleton'), $id);
			if (!$object->getId())
			{
				$controller->addError('Cet &eacute;lement semble introuvable ! Contactez le webmaster si l\'erreur persiste');
				$controller->forward('displayList');
			}
			else
			{
				$commentary = null;
				if (isset($_POST['commentary']))
					$commentary = $_POST['commentary'];
				
				switch ($element)
				{
					case 'book' :
						$controller->setVar('ratingList', $object->getRatingList());
						break;
					case 'serie' :
						$object->loadView();
						$controller->setVar('ratingList', $object->getRatingList());
						break;
					case 'author' :
						$object->loadView();
						break;
					case 'publisher' :
						$object->loadView();
						break;
				
				}
				
				$controller->setVar('commentary', $commentary);
				$controller->setVar($element,$object);
				$controller->setVar('user',$user);
				$controller->setVar('id',$id);
				$controller->render('view'.$element);
			}
		}
	}
	else
		$controller->render('errorRights');

?>